﻿using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;


namespace ABELGX
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        public Driver Work {  get;private set; }
        protected override void OnStartup(StartupEventArgs e)
        {
            bool bWork = false;
            Mutex mutex = new Mutex(false, "ABELGX", out bWork);
            bool Running = !mutex.WaitOne(0, false);

            if (!Running)
            {
                Config.Init();
                switch(Config.Device)
                {
                    case DeviceType.PG:
                        StartupUri = new Uri("/Device/PG/WindowPG.xaml", UriKind.Relative);
                        break;
                    case DeviceType.V139:
                        break;
                }
                Work = new Driver();
                base.OnStartup(e);
            }
            else
            {
                MessageBox.Show("已经打开，请勿重复打开！");
                Environment.Exit(0);
            } 
        }
        protected override void OnExit(ExitEventArgs e)
        {
            try
            {
                Config.SaveLog();
                Work.Stop();
            }
            catch
            {

            }
            base.OnExit(e);
        }
    }
}
